﻿<views:MvxWpfView 
    x:Class="Sidvall.IdentityManager.UI.Wpf.Views.AspNetUsersView"
    xmlns:Controls="clr-namespace:Sidvall.IdentityManager.UI.Wpf.Controls" 
    xmlns:Converters="clr-namespace:Sidvall.UI.Wpf.Converters;assembly=Sidvall.UI.Wpf" 
    xmlns:views="clr-namespace:MvvmCross.Wpf.Views;assembly=MvvmCross.Wpf"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:vms="clr-namespace:Sidvall.IdentityManager.UI.ViewModels;assembly=Sidvall.IdentityManager.UI"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
    xmlns:local="clr-namespace:Sidvall.IdentityManager.UI.Wpf.Views"
    mc:Ignorable="d" 
    d:DesignHeight="550" d:DesignWidth="800">

    <UserControl.Resources>
        <Converters:InverseBooleanConverter x:Key="InverseBooleanConverter"/>
        <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" Collapsed="False" />
    </UserControl.Resources>
    
    <Grid d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type={x:Type vms:AspNetUsersViewModel}}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition/>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Controls:HeaderControl HeaderCaption="{Binding Title}" />
            <TabControl Grid.Row="2" Margin="0,5,0,0">
                <TabItem Header="Information">
                    <Grid Margin="0,0,5,0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition/>
                        </Grid.RowDefinitions>

                        <StackPanel>
                            <Grid Margin="0,5,0,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="160" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <Label Grid.Column="0" Grid.Row="0" Content="Id:" />
                                <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding ActiveEntity.Id, Mode=OneWay}" IsReadOnly="True" />
                            </Grid>
                            <Grid Margin="0,5,0,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="160" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <Label Grid.Column="0" Grid.Row="0" Content="Name:" />
                                <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding ActiveEntity.Name}" />
                            </Grid>
                            <Grid Margin="0,5,0,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="160" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <Label Grid.Column="0" Grid.Row="0" Content="User name:" />
                                <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding ActiveEntity.UserName}" />
                            </Grid>
                            <Grid Margin="0,5,0,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="160" />
                                    <ColumnDefinition />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <Label Grid.Column="0" Grid.Row="0" Content="Email:" />
                                <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding ActiveEntity.Email}" />
                                <CheckBox Grid.Column="2" IsChecked="{Binding ActiveEntity.EmailConfirmed}" VerticalContentAlignment="Center" Padding="5,0,0,0" Margin="10,0,0,0" VerticalAlignment="Center">
                                    Confirmed
                                </CheckBox>
                            </Grid>
                            <Grid Margin="0,5,0,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="160" />
                                    <ColumnDefinition />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <Label Grid.Column="0" Grid.Row="0" Content="Phone Number:" />
                                <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding ActiveEntity.PhoneNumber}" />
                                <CheckBox Grid.Column="2" IsChecked="{Binding ActiveEntity.PhoneNumberConfirmed}" VerticalContentAlignment="Center" Padding="5,0,0,0" Margin="10,0,0,0" VerticalAlignment="Center">
                                    Confirmed
                                </CheckBox>
                            </Grid>
                            <Grid Margin="0,5,0,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="160" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <Label Grid.Column="0" Grid.Row="0" Content="Two Factor Authentication:" />
                                <CheckBox Grid.Column="1" IsChecked="{Binding ActiveEntity.TwoFactorEnabled}" VerticalContentAlignment="Center" Padding="0" VerticalAlignment="Center" />
                            </Grid>
                            <Grid Margin="0,5,0,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="160" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="160" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <Label Grid.Column="0" Content="Lockout:" />
                                <CheckBox Grid.Column="1" IsChecked="{Binding ActiveEntity.LockoutEnabled}" VerticalContentAlignment="Center" Padding="0" VerticalAlignment="Center" />
                                <Label Grid.Column="2" Content="ends at:" />
                                <xctk:DateTimePicker Grid.Column="3" Value="{Binding ActiveEntity.LockoutEndDateUtc}" Format="Custom" FormatString="yyyy-MM-dd HH:mm:ss" />
                            </Grid>
                            <Grid Margin="0,5,0,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="160" />
                                    <ColumnDefinition Width="100" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <Label Grid.Column="0" Grid.Row="0" Content="Access Failed Count:" />
                                <xctk:IntegerUpDown Grid.Column="1" Minimum="0" Value="{Binding ActiveEntity.AccessFailedCount}" ClipValueToMinMax="True" ParsingNumberStyle="Integer" />
                            </Grid>
                        </StackPanel>
                        <TabControl Grid.Row="1" Margin="0,5,0,0">
                            <TabItem Header="Claims">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>

                                    <Grid>
                                        <Grid.Background>
                                            <SolidColorBrush Color="#FFD1E0F1" Opacity="0.6"/>
                                        </Grid.Background>
                                        <StackPanel Orientation="Horizontal">
                                            <Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.IdentityManager.UI.Wpf;component/Images/Add.png" 
                                            ToolTip="Add User Claim" ButtonCommand="{Binding AddUserClaimCommand}" />
                                        </StackPanel>
                                    </Grid>

                                    <DataGrid Grid.Row="1" RowHeaderWidth="0" ItemsSource="{Binding UserClaims}" AutoGenerateColumns="False" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserAddRows="False">
                                        <DataGrid.Columns>
                                            <DataGridTemplateColumn Width="250" Header="Type">
                                                <DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <ComboBox IsEditable="True" ItemsSource="{Binding DataContext.Claims, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:AspNetUsersView}}}" DisplayMemberPath="ClaimType" SelectedValuePath="ClaimType" Text="{Binding ClaimType, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" />
                                                    </DataTemplate>
                                                </DataGridTemplateColumn.CellTemplate>
                                            </DataGridTemplateColumn>
                                            <DataGridTemplateColumn Width="*" Header="Value">
                                                <DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <TextBox Text="{Binding ClaimValue, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" TextWrapping="Wrap" />
                                                    </DataTemplate>
                                                </DataGridTemplateColumn.CellTemplate>
                                            </DataGridTemplateColumn>
                                            <DataGridTemplateColumn Width="35" IsReadOnly="True">
                                                <DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <Button Width="32" Height="32" Background="{x:Null}" BorderBrush="{x:Null}" 
                                                            Command="{Binding DataContext.DeleteUserClaimCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:AspNetUsersView}}}"
                                                            CommandParameter="{Binding}">
                                                            <Image Source="/Sidvall.IdentityManager.UI.Wpf;component/Images/Delete.png" ToolTip="Delete User Claim" />
                                                        </Button>
                                                    </DataTemplate>
                                                </DataGridTemplateColumn.CellTemplate>
                                            </DataGridTemplateColumn>
                                        </DataGrid.Columns>
                                    </DataGrid>
                                </Grid>
                            </TabItem>
                            <TabItem Header="Login Providers">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>

                                    <Grid>
                                        <Grid.Background>
                                            <SolidColorBrush Color="#FFD1E0F1" Opacity="0.6"/>
                                        </Grid.Background>
                                        <StackPanel Orientation="Horizontal">
                                            <Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.IdentityManager.UI.Wpf;component/Images/Add.png" 
                                            ToolTip="Add User Login" ButtonCommand="{Binding AddUserLoginCommand}" />
                                        </StackPanel>
                                    </Grid>

                                    <DataGrid Grid.Row="1" RowHeaderWidth="0" ItemsSource="{Binding ActiveEntity.AspNetUserLogins}" AutoGenerateColumns="False" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserAddRows="False">
                                        <DataGrid.Columns>
                                            <DataGridTemplateColumn Width="250" Header="Login Provider">
                                                <DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <TextBox Text="{Binding LoginProvider, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" IsReadOnly="{Binding IsNew, Mode=OneWay, Converter={StaticResource InverseBooleanConverter}}" TextWrapping="Wrap"  />
                                                    </DataTemplate>
                                                </DataGridTemplateColumn.CellTemplate>
                                            </DataGridTemplateColumn>
                                            <DataGridTemplateColumn Width="*" Header="Provider Key">
                                                <DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <TextBox Text="{Binding ProviderKey, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" IsReadOnly="{Binding IsNew, Mode=OneWay, Converter={StaticResource InverseBooleanConverter}}" TextWrapping="Wrap"  />
                                                    </DataTemplate>
                                                </DataGridTemplateColumn.CellTemplate>
                                            </DataGridTemplateColumn>
                                            <DataGridTemplateColumn Width="35" IsReadOnly="True">
                                                <DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <Button Width="32" Height="32" Background="{x:Null}" BorderBrush="{x:Null}" 
                                                            Command="{Binding DataContext.DeleteUserLoginCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:AspNetUsersView}}}"
                                                            CommandParameter="{Binding}">
                                                            <Image Source="/Sidvall.IdentityManager.UI.Wpf;component/Images/Delete.png" ToolTip="Delete User Login" />
                                                        </Button>
                                                    </DataTemplate>
                                                </DataGridTemplateColumn.CellTemplate>
                                            </DataGridTemplateColumn>
                                        </DataGrid.Columns>
                                    </DataGrid>
                                </Grid>
                            </TabItem>
                            <TabItem Header="Password">
                                <Grid>
                                    <StackPanel>
                                        <Grid Margin="0,5,0,0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="160" />
                                                <ColumnDefinition />
                                            </Grid.ColumnDefinitions>

                                            <Label Grid.Column="0" Grid.Row="0" Content="Password:" />
                                            <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding VerifyPassword}" />
                                        </Grid>
                                        <Grid Margin="0,5,0,0">
                                            <Button Command="{Binding VerifyPasswordCommand}" IsEnabled="{Binding CanVerifyPassword}" Padding="10,1" Width="150" HorizontalAlignment="Left">
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition />
                                                    </Grid.ColumnDefinitions>

                                                    <Image Source="/Sidvall.IdentityManager.UI.Wpf;component/Images/Save.png" Width="24"/>
                                                    <TextBlock Grid.Column="1" Text="Verify Password" Margin="5,0,0,0" VerticalAlignment="Center" />
                                                </Grid>
                                            </Button>
                                        </Grid>

                                        <Rectangle Margin="0,15,5,5" StrokeEndLineCap="Round" Height="3" Fill="#FF23232B" >
                                            <Rectangle.Effect>
                                                <DropShadowEffect/>
                                            </Rectangle.Effect>
                                        </Rectangle>

                                        <Grid Margin="0,5,0,0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="160" />
                                                <ColumnDefinition />
                                            </Grid.ColumnDefinitions>

                                            <Label Grid.Column="0" Grid.Row="0" Content="New Password:" />
                                            <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding NewPassword}" />
                                        </Grid>
                                        <Grid Margin="0,5,0,0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition />
                                            </Grid.ColumnDefinitions>

                                            <Button Command="{Binding ResetPasswordCommand}" IsEnabled="{Binding CanResetPassword}" Padding="10,1" Width="150" HorizontalAlignment="Left">
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition />
                                                    </Grid.ColumnDefinitions>

                                                    <Image Source="/Sidvall.IdentityManager.UI.Wpf;component/Images/Save.png" Width="24"/>
                                                    <TextBlock Grid.Column="1" Text="Update Password" Margin="5,0,0,0" VerticalAlignment="Center" />
                                                </Grid>
                                            </Button>
                                            <Button Grid.Column="1" Command="{Binding SendResetPasswordEmailCommand}" Padding="10,1" Width="Auto" HorizontalAlignment="Left" Margin="10,0,0,0">
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition />
                                                    </Grid.ColumnDefinitions>

                                                    <Image Source="/Sidvall.IdentityManager.UI.Wpf;component/Images/ConnectToServer.png" Width="24"/>
                                                    <TextBlock Grid.Column="1" Text="Send Reset Password Email" Margin="5,0,0,0" VerticalAlignment="Center" />
                                                </Grid>
                                            </Button>
                                        </Grid>
                                    </StackPanel>
                                </Grid>
                            </TabItem>
                        </TabControl>
                    </Grid>
                </TabItem>
                <TabItem Header="{Binding Plugin1.Title}" Visibility="{Binding Plugin1.ShowEditView, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <ContentControl x:Name="PluginContent1" />
                </TabItem>
                <TabItem Header="{Binding Plugin2.Title}" Visibility="{Binding Plugin2.ShowEditView, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <ContentControl x:Name="PluginContent2" />
                </TabItem>
                <TabItem Header="{Binding Plugin3.Title}" Visibility="{Binding Plugin3.ShowEditView, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <ContentControl x:Name="PluginContent3" />
                </TabItem>
                <TabItem Header="{Binding Plugin4.Title}" Visibility="{Binding Plugin4.ShowEditView, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <ContentControl x:Name="PluginContent4" />
                </TabItem>
                <TabItem Header="{Binding Plugin5.Title}" Visibility="{Binding Plugin5.ShowEditView, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <ContentControl x:Name="PluginContent5" />
                </TabItem>
            </TabControl>
            <Grid Grid.Row="3" Margin="0,5,0,5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <Button Grid.Column="1" Command="{Binding SaveCommand}" IsEnabled="{Binding IsSavable}" Padding="10,1" Margin="5,0,0,0">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <Image Source="/Sidvall.IdentityManager.UI.Wpf;component/Images/Save.png" Width="24"/>
                        <TextBlock Grid.Column="1" Text="Save" Margin="5,0,0,0" VerticalAlignment="Center" />
                    </Grid>
                </Button>
            </Grid>
        </Grid>
    </Grid>
</views:MvxWpfView>
